package com.shd.edanpei.base.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shd.edanpei.BuildConfig;
import com.shd.edanpei.R;
import com.shd.edanpei.base.TranBarActivity;
import com.shd.edanpei.base.network.ApiConstant;
import com.shd.edanpei.base.network.api.ApiCreator;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.presenter.LoginPresenter;
import com.shd.edanpei.ui.activity.LoginActivity;
import com.shd.edanpei.util.DateUtils;
import com.shd.edanpei.util.ToastUtil;

public class DialogUtils {



public  Long times2;
    @SuppressLint("ResourceType")
    public    void showDialog(final Context context, final  String phonse, final String type, final LoginPresenter loginPresenter){
        final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
        View view= LinearLayout.inflate(context,R.layout.activity_dialog_layout,null);
        alertDialog.setView(view);
        final ImageView imageView=view.findViewById(R.id.img_vrit_code);
        times2 = System.currentTimeMillis();

        Glide.with(context).load(BuildConfig.IS_RELEASE_URL?ApiConstant.BASE_RELEASE_URL:ApiConstant.BASE_DEBUG_URL+"picCode/getImage?uuid="+ times2).into(imageView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 times2 =System.currentTimeMillis();

                Glide.with(context).load(BuildConfig.IS_RELEASE_URL?ApiConstant.BASE_RELEASE_URL:ApiConstant.BASE_DEBUG_URL+"picCode/getImage?uuid="+ times2).into(imageView);
            }
        });
        final EditText editText=view.findViewById(R.id.edit_vrit_code);
        alertDialog.setPositiveButton("提交", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if(editText.getText().toString().isEmpty()){
                    ToastUtil.showToast("请输入验证码！");
                    return;
                }
                if(type.equals("1")){
                    loginPresenter.getCAPTCHA(phonse, times2 +"",editText.getText().toString());
                }else{
                    loginPresenter.getLoginCode(phonse, times2+"",editText.getText().toString());
                }
                dialog.dismiss();
            }
        });
        AlertDialog dialog= alertDialog.show();
        Button b = dialog.findViewById(android.R.id.button1);
        b.setGravity(Gravity.CENTER_HORIZONTAL);


    }
}
